<?php

namespace app\xwam\model;

/**
 * 敏感词 模型类
 *
 * @version 1.0 2017-3-24 SoChishun(14507247@qq.com) Added.
 */
class SensitiveWordsModel extends AppbaseModel {

    protected $table = 't_common_dict';

    /**
     * 保存单个配置
     * @return type
     */
    function saveConf() {
        $data = input('post.');
        $isAdd = empty($data['id']);
        unset($data['tab']);
        if ($isAdd) {
            unset($data['id']);
            $result = $this->isUpdate(false)->save($data);
        } else {
            $result = $this->isUpdate(true)->save($data);
        }
        return xsfn_message($result);
    }

    // 2017-3-24
    public function testContent($str) {
        $where = array('title' => 'SensitiveWords-Content', 'conf_group' => 'SensitiveWords');
        $data = $this->where($where)->getField('lcontent');
        $awords = explode(',', $data);
        $awords1 = array_combine($awords, array_fill(0, count($awords), '*'));
        $str = strtr($str, $awords1);
        return $str;
    }

}
